package com.allm.ai.common.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * AI模型实体类
 */
@Data
@Entity
@Table(name = "ai_model")
@EntityListeners(AuditingEntityListener.class)
@EqualsAndHashCode(callSuper = false)
public class AiModel {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "name", nullable = false, unique = true, length = 100)
    private String name;

    @Column(name = "display_name", nullable = false, length = 100)
    private String displayName;

    @Column(name = "request_model_name", length = 100)
    private String requestModelName; // 请求时使用的模型名称

    @Column(name = "icon", nullable = false, length = 10)
    private String icon;

    @Column(name = "api_endpoint", nullable = false)
    private String apiEndpoint;

    @Column(name = "api_key")
    private String apiKey;

    // 添加百度千帆专用字段
    @Column(name = "ak", length = 200)
    private String ak; // Access Key

    @Column(name = "sk", length = 200)
    private String sk; // Secret Key

    @Column(name = "service_provider", nullable = false, length = 50)
    private String serviceProvider;

    @Column(name = "model_type", nullable = false, length = 50)
    private String modelType;

    @Column(name = "is_free")
    private Boolean isFree = false;

    @Column(name = "is_active")
    private Boolean isActive = true;

    @Column(name = "sort_order", precision = 10, scale = 2)
    private BigDecimal sortOrder = BigDecimal.ONE;

    @Column(name = "max_tokens")
    private Integer maxTokens = 4096;

    @Column(name = "temperature", precision = 3, scale = 2)
    private BigDecimal temperature = new BigDecimal("0.7");

    @Column(name = "description", columnDefinition = "TEXT")
    private String description;

    // 推理能力相关字段
    @Column(name = "reason_support")
    private Boolean reasonSupport = false; // 是否支持推理

    @Column(name = "reasoning_enable")
    private Boolean reasoningEnable = false; // 是否启用推理能力

    // 显示配置字段
    @Column(name = "icon_class", length = 100)
    private String iconClass = "fas fa-robot";

    @Column(name = "color_class", length = 100)
    private String colorClass = "bg-gray-100 text-gray-600";

    @Column(name = "model_description", columnDefinition = "TEXT")
    private String modelDescription;

    @Column(name = "rank_position")
    private Integer rankPosition = 0;

    @Column(name = "flowers_count")
    private Integer flowersCount = 0;

    @Column(name = "eggs_count")
    private Integer eggsCount = 0;

    @Column(name = "popularity_score")
    private Integer popularityScore = 0;

    @Column(name = "discussions_count")
    private Integer discussionsCount = 0;

    @Column(name = "response_speed_score", precision = 3, scale = 1)
    private BigDecimal responseSpeedScore = BigDecimal.ZERO;

    @Column(name = "accuracy_score", precision = 3, scale = 1)
    private BigDecimal accuracyScore = BigDecimal.ZERO;

    @Column(name = "copywriting_score", precision = 3, scale = 1)
    private BigDecimal copywritingScore = BigDecimal.ZERO;

    @Column(name = "drawing_score", precision = 3, scale = 1)
    private BigDecimal drawingScore = BigDecimal.ZERO;

    @Column(name = "programming_score", precision = 3, scale = 1)
    private BigDecimal programmingScore = BigDecimal.ZERO;

    @CreatedDate
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @LastModifiedDate
    @Column(name = "updated_time")
    private LocalDateTime updatedTime;

    @CreatedBy
    @Column(name = "created_by", length = 50)
    private String createdBy;

    @LastModifiedBy
    @Column(name = "updated_by", length = 50)
    private String updatedBy;
}